# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class BaidustocksPipeline:
    def process_item(self, item, spider):
        return item
class BaidustocksInfoPipeline(object):
    def open_spider(self,spider):#爬虫被调用时对应的pipeline启动的方法
        self.f = open('BaiduStockInfo.txt','w')
    def close_spider(self,spider):
        self.f.close()#爬虫关闭或结束时pipeline对应的方法
    def process_item(self,item,spider):#对每一个item项进行处理时对应的方法 pipeline最主体的函数
        #打开关闭
        try:
            line = str(dict(item)) + '\n'
            self.f.write(line)
        except:
            pass
        return item



